﻿using System;
using System.ComponentModel;

namespace Ams.Extensions
{
    public static class EnumExtensions
    {
        public static string GetDisplayText(this Enum enm)
        {
            var fieldName = enm.ToString();

            var description = enm.GetType().GetField(fieldName).Attribute<DescriptionAttribute>();

            if (description != null)
            {
                return description.Description;
            }

            var displayName = fieldName.Titlize();
            return displayName;
        }
    }
}
